import { ADType, SDKInfo, getSDK } from "./SDKDefine";
import { SDKAdMgr } from "./ad/SDKAdMgr";
import SDKFactory from "./adapter/SDKFactory";
import SDKFileSystem from "./core/SDKFileSystem";
import SDKLogin from "./core/SDKLogin";
import SDKRecorder from "./core/SDKRecorder";
import SDKScreenShot from "./core/SDKScreenShot";
import SDKShare from "./core/SDKShare";
import SDKSubpackage from "./core/SDKSubpackage";

/**
 * sdk的其他能力
 */
export class SDKManager {

    static share: SDKShare = null;

    static fileSystem: SDKFileSystem = null;

    static screenShot: SDKScreenShot = null;

    static subpackage: SDKSubpackage = null;

    static login: SDKLogin = null;

    static recorder: SDKRecorder = null;

    //激励视频
    static reward: SDKAdMgr = null;
    //banner
    static banner: SDKAdMgr = null;

    static block: SDKAdMgr = null;

    static portal: SDKAdMgr = null;


    static init(config: SDKInfo) {
        // let config = configMap[cid];
        let sdk = SDKFactory.sdk;
        console.log(' sdk is -=-=----- ', sdk)
        if (!sdk) {
            return;
        }
        if (!config) {
            console.log(' init error')
            return;
        }



        for (let index = 0; index < config.ads.length; index++) {
            const cfg: ADType = config.ads[index];
            if (cfg.name && cfg.ids.length > 0) {
                this[cfg.name] = SDKAdMgr.create(cfg)
            } else {
                console.warn(' name is null or ids is zero', cfg)
            }
        }
        if (config.share && sdk.hasShare()) {
            this.share = new SDKShare();
            this.share.init(config.share)
        }

        if (sdk.hasSubpackage()) {
            this.subpackage = new SDKSubpackage()
        }

        if (sdk.hasRecorder()) {
            this.recorder = new SDKRecorder();
        }

        if (sdk.getFileSystemManager()) {
            this.fileSystem = new SDKFileSystem()
        }

        if (sdk.login) {
            this.login = new SDKLogin();
        }

        if (sdk.hasPreviewImage) {
            this.screenShot = new SDKScreenShot()
        }



    }

}
